//
//  BusinessMatchMakingViewController.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/3/30.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "BusinessMatchMakingViewController.h"
#import "ProjectWithArrowButton.h"
#import "XXTool.h"

#import "ProductInformationShowViewController.h"
#import "XVCReleaseProduct.h"
#import "PersonInfoViewController.h"
#import "VisitorInfoController.h"

@interface BusinessMatchMakingViewController ()<UIAlertViewDelegate>

@property (nonatomic) UIImageView * background;

@property (nonatomic) UIScrollView *content;

@property (nonatomic) ProjectWithArrowButton *exhibitor;

@property (nonatomic) ProjectWithArrowButton *vistor;

@property (nonatomic) UILabel *exhibitorTipLabel;

@property (nonatomic) UILabel *vistorTipLabel;

@end

@implementation BusinessMatchMakingViewController
{
    CGFloat labelWidth;
    CGFloat buttonWidth;
    CGFloat buttonHeight;
    CGFloat controlGap;
}

-(UIImageView*)background
{
    if (_background==nil)
    {
        _background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"商贸配对背景图"]];
        _background.contentMode = UIViewContentModeScaleAspectFill;
        [self.view addSubview:_background];
    }
    return _background;
}

-(UIScrollView*)content
{
    if (_content==nil)
    {
        _content = [[UIScrollView alloc] init];
        _content.backgroundColor = [UIColor clearColor];
        [self.view addSubview:_content];
    }
    return _content;
}

-(ProjectWithArrowButton*)exhibitor
{
    if (_exhibitor==nil)
    {
        _exhibitor = [[ProjectWithArrowButton alloc] init];
        [_exhibitor setButtonWithText:NSLocalizedString(@"我是展商", nil)];
        [_exhibitor addTarget:self Select:@selector(clickBusinessExhibitorButton) ForEvent:DKButtonEventPressedEnd];
        [_content addSubview:_exhibitor];
    }
    return _exhibitor;
}

-(ProjectWithArrowButton*)vistor
{
    if (_vistor==nil)
    {
        _vistor = [[ProjectWithArrowButton alloc] init];
        [_vistor setButtonWithText:NSLocalizedString(@"我是观众", nil)];
        [_vistor addTarget:self Select:@selector(clickBusinessVisitorButton) ForEvent:DKButtonEventPressedEnd];
        [_content addSubview:_vistor];
    }
    return _vistor;
}

-(UILabel*)vistorTipLabel
{
    if (_vistorTipLabel==nil)
    {
        _vistorTipLabel = [[UILabel alloc] init];
        _vistorTipLabel.text = @"查看所有参展商发布的展品信息，收藏你感兴趣的展商名片，对你想建立合作关系的展商发送预约参观的请求。\n\rLook over all the exhibits, collect exhibitors' business cards, submit the requirement of visit appointment.";
        _vistorTipLabel.font = [XXTool systemFontOfSize:14];
        _vistorTipLabel.textColor = [UIColor whiteColor];
        _vistorTipLabel.numberOfLines = 0;
        _vistorTipLabel.textAlignment = NSTextAlignmentCenter;
        [_content addSubview:_vistorTipLabel];
    }
    return _vistorTipLabel;
}

-(UILabel*)exhibitorTipLabel
{
    if (_exhibitorTipLabel==nil)
    {
        _exhibitorTipLabel = [[UILabel alloc] init];
        _exhibitorTipLabel.textAlignment = NSTextAlignmentCenter;
        _exhibitorTipLabel.textColor = [UIColor whiteColor];
        _exhibitorTipLabel.font = [XXTool systemFontOfSize:14];
        _exhibitorTipLabel.numberOfLines = 0;
        _exhibitorTipLabel.text = @"发布您的展品信息，让更多人了解你们的产品，并且能收到来自观众的预约请求\n\rpublish your exhibits, make your exhibits more well-known, receive appointment request from audience.";
        [_content addSubview:_exhibitorTipLabel];
    }
    return _exhibitorTipLabel;
}

-(void)initParameter
{
    labelWidth = 285;
    buttonWidth = 250;
    buttonHeight = 50;
    controlGap = 15;
}

-(void)initUI
{
    [self.navigationItem setTitle:NSLocalizedString(@"商贸配对", nil)];
    
    [self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"更多"] style:UIBarButtonItemStylePlain target:self action:@selector(clickleft)]];
    
    [self background];
    [self content];
    [self vistor];
    [self vistorTipLabel];
    
    
    if ([UserInfo shareUserInfo].isExhibitor)
    {
        [self exhibitor];
        [self exhibitorTipLabel];
    }
    
}
CGRect fr;
-(void)refreshLayout:(CGRect)frame
{
    fr=frame;
    _background.frame = CGRectMake(0, 0, frame.size.width
                                   , frame.size.height);
    _content.frame = CGRectMake(0, 0, frame.size.width
                                 , frame.size.height);
    
    CGFloat tipVisitorHeigth = [XXTool getTextHeightByText:_vistorTipLabel.text
                                                     Font:_vistorTipLabel.font
                                                    Width:labelWidth];
    CGFloat tipExhibitorHeight = [XXTool getTextHeightByText:_exhibitorTipLabel.text
                                                       Font:_exhibitorTipLabel.font
                                                      Width:labelWidth];
    CGFloat allControlheight = 0;
    if ([UserInfo shareUserInfo].isExhibitor)
    {
        allControlheight = tipVisitorHeigth+tipExhibitorHeight+buttonHeight*2+controlGap*3;
    }
    else
    {
        allControlheight = tipVisitorHeigth+buttonHeight+controlGap;
    }
    
    if (allControlheight<frame.size.height)
    {
        _vistor.frame = CGRectMake((frame.size.width-buttonWidth)/2
                                   , (frame.size.height-allControlheight)/2
                                   , buttonWidth
                                   , buttonHeight);
        _vistorTipLabel.frame = CGRectMake((frame.size.width-labelWidth)/2
                                           , _vistor.frame.size.height+_vistor.frame.origin.y+controlGap
                                           , labelWidth
                                           , tipVisitorHeigth);
        if ([UserInfo shareUserInfo].isExhibitor)  // 展商登陆
        {
            if(_exhibitor != nil){
                [_exhibitor setHidden:NO];
                [_exhibitorTipLabel setHidden:NO];
            }
            _exhibitor.frame = CGRectMake(_vistor.frame.origin.x
                                          , _vistorTipLabel.frame.size.height+_vistorTipLabel.frame.origin.y+controlGap
                                          , buttonWidth
                                          , buttonHeight);
            _exhibitorTipLabel.frame = CGRectMake(_vistorTipLabel.frame.origin.x
                                                  , _exhibitor.frame.size.height+_exhibitor.frame.origin.y+controlGap
                                                  , labelWidth
                                                  , tipExhibitorHeight);
        }else{
            if(_exhibitor != nil){
                [_exhibitor setHidden:YES];
                [_exhibitorTipLabel setHidden:YES];
            }
        }
        _content.contentSize = CGSizeMake(frame.size.width
                                          , frame.size.height);
    }
    else
    {
        _vistor.frame = CGRectMake((frame.size.width-buttonWidth)/2
                                   , 50
                                   , buttonWidth
                                   , buttonHeight);
        _vistorTipLabel.frame = CGRectMake((frame.size.width-labelWidth)/2
                                           , _vistor.frame.size.height+_vistor.frame.origin.y+controlGap
                                           , labelWidth
                                           , tipVisitorHeigth);
        
        if ([UserInfo shareUserInfo].isExhibitor)
        {
            _exhibitor.frame = CGRectMake(_vistor.frame.origin.x
                                          , _vistorTipLabel.frame.size.height+_vistorTipLabel.frame.origin.y+controlGap
                                          , buttonWidth
                                          , buttonHeight);
            _exhibitorTipLabel.frame = CGRectMake(_vistorTipLabel.frame.origin.x
                                                  , _exhibitor.frame.size.height+_exhibitor.frame.origin.y+controlGap
                                                  , labelWidth
                                                  , tipExhibitorHeight);
            _content.contentSize = CGSizeMake(frame.size.width
                                              , allControlheight+100);
        }
        else
        {
            _content.contentSize = CGSizeMake(frame.size.width
                                              , frame.size.height);
        }
        
    }
    
}

-(void)clickleft
{
    //[self.navigationController.sideViewController showLeftView];
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)clickBusinessVisitorButton
{
    [self.navigationController pushViewController:[[ProductInformationShowViewController alloc] init] animated:YES];
}

-(void)clickBusinessExhibitorButton
{
    if ([[UserInfo shareUserInfo].userName isEqualToString:@""]||[UserInfo shareUserInfo].userName==nil)
    {
        [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"提示", nil)
                                   message:NSLocalizedString(@"请去补充您的个人资料", nil)
                                  delegate:self
                         cancelButtonTitle:NSLocalizedString(@"取消", nil)
                         otherButtonTitles:NSLocalizedString(@"确定", nil), nil] show];
       
        return;
    }
    [self.navigationController pushViewController:[[VisitorInfoController alloc] init] animated:YES];
}

#pragma mark alertviewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex==1)
    {
        [PersonInfoViewController pushPersonInfoVCWithSourceVC:self personInfoViewControllerType:PersonInfoViewControllerSupplyExhibitorInformation];
    }
}


@end
